﻿using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace Hotel.API.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class CommonsController : ControllerBase
    {
        [HttpPost]
        public IActionResult GetImgUrl(IFormFile file)
        {
            try
            {
                string newfile = Directory.GetCurrentDirectory()+@"\wwwroot\imgs\"+file.FileName;
                using (FileStream fs = new FileStream(newfile,FileMode.Create))
                {
                    file.CopyTo(fs);
                    fs.Close();
                }
                return Ok("https://localhost:7236/imgs/" + file.FileName);
            }
            catch (Exception)
            {

                throw;
            }
        } 
    }
}
